package cn.kgc.springboot.vue.handlers;

import cn.kgc.springboot.vue.exception.BusinessException;
import cn.kgc.springboot.vue.response.ResponseResult;
import cn.kgc.springboot.vue.response.ResponseStatus;
import org.apache.shiro.authz.UnauthorizedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 课工场
 * @date 2024/12/20
 * @description
 */
@RestControllerAdvice
public class GlobalExceptionHandler {


    @ExceptionHandler(Exception.class)
    public ResponseResult   allExceptionHandler(Exception e){
        e.printStackTrace();
        return  ResponseResult.error();
    }

    @ExceptionHandler(BusinessException.class)
    public ResponseResult   businessExceptionHandler(BusinessException e){
        return  ResponseResult.error().message(e.getInfo());
    }

    @ExceptionHandler(UnauthorizedException.class)
    public ResponseResult   unauthorizedExceptionHandler(UnauthorizedException e){
        return  ResponseResult.error().code(ResponseStatus.UN_AUTHOR).message(ResponseStatus.UN_AUTHOR.getMessage());
    }

}
